import { reqGetCode, reqUserRegister } from "@/api";
//仓库存储数据的地方
const state = {
    code: {},
};
//修改state的唯一手段
const mutations = {
    GETCODE(state, code) {
        state.code = code;
    }
};
//处理action，可以书写自己的业务逻辑，也可以处理异步
const actions = {
    //获取验证码
    async getCode({ commit }, phone) {
        let result = await reqGetCode(phone);
        console.log(result);
        if (result.code == 200) {
            commit('GETCODE', result.data);
            return 'ok'
        } else {
            return Promise.reject(new Error('faile'));
        }
    },
    //注册
    async userRegister({ commit }, user) {
        let result = await reqUserRegister(user);
        console.log(result);
        if (result.code == 200) {
            return 'ok';
        } else {
            return Promise.reject(new Error('faile'));
        }
    }
};
//理解为计算属性，用于简化仓库数据，让组件获取仓库的数据更加方便
const getters = {};
// 对外暴露store类的一个实例
export default ({
    state,
    mutations,
    actions,
    getters
})